<?php
$isReloadable = true;
require_once("../../../pers/inc.config.php");
require_once(OVF_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(OVF_FS_WEB_ROOT.'/app/_inc/funct.html.php');
require_once OVF_FS_WEB_ROOT.'/app/_inc/class.ovfForm.php';

$objSess->setReqSV('rcom', 'idAnag', 0);
$idAnag = intval($objSess->getSV('rcom', 'idAnag'));

$aWhere[] = " a.id_anag = ".$idAnag;
$aWhere[] = " a.tipo_agenda IN ('I','C') ";

$sWhere = (empty($aWhere))?"":" WHERE ".implode (" AND ",$aWhere);

$sSql = "SELECT DISTINCT a.id_agenda, a.giorno, a.mese, a.anno, a.ora, a.minuti ".
      ", a.data_agenda, a.data_memo_iniz, a.tipo_agenda \n" .
      " FROM ovf_agenda a \n" .
      " $sWhere \n";
//dbg_($sSql);
$objDB->query($sSql,'selId');
$aId = array();
while($acX = $objDB->fetch('selId')) {
	$ymdX = $acX['data_agenda'];
	$aId[] = "A".$ymdX.lpad($acX['ora'],2,'0').lpad($acX['minuti'],2,'0').$acX['id_agenda'];
}
rsort($aId);
//dbg_($aId);
// testata sezione anagrafica
$oFormTestaSez = new ovfForm('testasez');
//dbg_($oForm);
$sSql = "SELECT ".$oFormTestaSez->getCampiSelect()
   ." FROM ovf_anagrafiche A WHERE A.id_anag = ".$idAnag;
$objDB->query($sSql);
if (!$oFormTestaSez->aCampiDB = $objDB->fetch()) {
   backOnErr("id. errato '".$idAnag."'");
}
$oFormTestaSez->db2form();

$sHtmlAnag = "<table class=\"tab1\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" align='center'>";
$sHtmlAnag .= getHtmlRigaRif();
$sHtmlAnag .= $oFormTestaSez->getHtmlCampiView();
$sHtmlAnag .= "</table>";

$sCmdL  = "";

$sCmdLX = "<a class=\"cmd1\" href=\"../anag/anagView.php?idAnag=".reqVar('idAnag')."&$sXSNQS\" >scheda anagrafica</a>&nbsp;&nbsp;&nbsp;\n";
$sCmdLX .= "&nbsp;&nbsp;&nbsp;<a class=\"cmd1\" href=\"../docu/docuList.php?idAnag=".reqVar('idAnag')."&$sXSNQS\" >documenti</a>&nbsp;&nbsp;&nbsp;\n";

$sCmdR  = "";

$sCmdR .= "&nbsp;&nbsp;&nbsp;<a class=\"cmd1\" href=\"../../agen/impeIns.php?listIdAge=".$objSess->idUtente
   ."&anagX=".urlencode($oFormTestaSez->aCampiDB['A_intestaz1']." (".$oFormTestaSez->aCampiDB['A_id_anag'].")")
   ."&$sXSNQS\" >fissa impegno</a>\n";
$sCmdR .= "&nbsp;&nbsp;&nbsp;<a class=\"cmd1\" href=\"contIns.php?idAnag=".$oFormTestaSez->aCampiDB['A_id_anag']
   ."&$sXSNQS\" >registra contatto</a>\n";
$sCmdR .=  cmdTorna();

$aOpz['sottotit'] = $sHtmlAnag;

testaHtml(_t('Anagrafe'),_t('Lista contatti'), $msgPag, 'rcom', $aOpz);
?>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='bottom'>
         <? echo $sCmdLX;?>
      </td>
      <td class="cmd1" align="right" valign='bottom'>
         <? echo $sCmdR;?>
      </td>
   </tr>
</table>
<form name='frm1' action='<?=$_SERVER['PHP_SELF']?>' method='post' enctype="multipart/form-data">
<input type='hidden' name='azione' value="...">
<input type='hidden' name='xsn' value="<?=XSN?>">
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
<?php echo getHtmlRigaRif(20);?>
   <tr>
      <td class="tit1" colspan='20' align='center'>
         <?=_t("Contatti")?>
      </td>
   </tr>
   <tr>
      <td class="lab1" colspan='2' align='center'>
         <?=_t("Data")?>
      </td>
		<td class="lab1" colspan='12' align='center'>
			<?=_t("Oggetto")?>
		</td>
		<td class="lab1" colspan='6' align='center'>
			<?=_t("Tipo")?>
		</td>
	</tr>
<?php 
$conta=0;
$ymdOld = '';
$sCla = 'txt1';
$oDataX = new ovfDate();
foreach($aId as $kX => $sX) {
	$sSql = "SELECT a.*, CONCAT(u.cognome) AS nominativo, an.intestaz1 "
		.", ti.descr AS TI_des, ti.pallino AS TI_pallino "
      .", tc.descr AS TC_des, tc.pallino AS TC_pallino "
      ." FROM ovf_agenda a "
		." LEFT JOIN ovf_agenda_utenti au ON au.id_agenda = a.id_agenda "
		." LEFT JOIN ovf_utenti u ON u.id_utente = au.id_utente "
		." LEFT JOIN ovf_agenda_tipi_imp ti ON ti.id_tipo_imp = a.id_tipo_imp \n"
      ." LEFT JOIN ovf_agenda_tipi_cont tc ON tc.id_tipo_cont = a.id_tipo_cont \n"
      ." LEFT JOIN ovf_anagrafiche an ON an.id_anag = a.id_anag \n"
      ." WHERE a.id_agenda = ".substr($sX,15);
	$objDB->query($sSql,'selAge');	
	$acX = $acAge = $objDB->fetch('selAge');
	$sAge = '(';
	while($acX) {
		$sAge .= $acX['nominativo'].",";
		$acX = $objDB->fetch('selAge');
	}
	$sAge = substr($sAge,0,-1).')';
   if ($acAge['tipo_agenda']=='I') {
	  $sHref = OVF_URL_ROOT."/app/agen/impeView.php?id=".$acAge['id_agenda']."&$sXSNQS";
   } else {
     $sHref = OVF_URL_ROOT."/app/rcom/cont/contView.php?id=".$acAge['id_agenda']."&$sXSNQS";
   }
	$sCla = ($sCla=='txt1')?'txt2':'txt1';
	$sStyle = "";
	?>
	<tr>
		<td class="<?=$sCla?>" colspan='2' style='text-align:center;<?=$sStyle?>'>
			<?php 
			echo "<a href='$sHref' style='$sStyle' class='$sCla'>".YMD2DMY($acAge['data_agenda'])."</a>";;
			?>
		</td>
		<td class="<?=$sCla?>" colspan='12' style='padding-left:20px;text-indent:-15px;'>
			<?
        echo "<a href='$sHref' class='$sCla'>";
			echo $acAge['oggetto'];
			echo "</a>\n ";
         echo $sAge.' ';
			?>
		</td>
		<td class="<?=$sCla?>" colspan='6' align='left'>
			<?php 
         if ($acAge['tipo_agenda'] == 'C') {
            if ($acAge['TC_pallino']=='') {
            $pallinoImg = "vuoto.png";
            $des = "(c) ".$acAge['TC_des'];
            } else {
               $pallinoImg = $acAge['TC_pallino'].".gif" ;
               $des = "(c) ".$acAge['TC_des'];
            }
         } else {
            if ($acAge['TI_pallino']=='') {
            $pallinoImg = "vuoto.png";
            $des = "(a) ".$acAge['TI_des'];
            } else {
               $pallinoImg = $acAge['TI_pallino'].".gif" ;
               $des = "(a) ".$acAge['TI_des'];
            }
         }
         echo "<img src=\"".OVF_URL_ROOT."/app/_img/pallino_ti_$pallinoImg\" border='0'/>&nbsp;&nbsp;";
         echo $des;
 			?>
		</td>
	</tr>
<?php 
}
?>
</table>
</form>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='bottom'>
         <? echo $sCmdL;?>
      </td>
      <td class="cmd1" align="right" valign='bottom'>
         <? echo $sCmdR;?>
      </td>
   </tr>
</table>
<?
codaHtml();
exit();

